package com.bitaka.ws;

import java.sql.*;

import javax.swing.JOptionPane;
//import org.postgresql.f.*;




public class ConnectBase {
    
    /** Creates a new instance of connection */
   private Connection conn=null;
   
   
    public ConnectBase() {
		
		}
		
    public boolean dbConnect(){
	boolean ok = false;              
	try {
             try {
                //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
								Class.forName("org.postgresql.Driver");
								//Class.forName("oracle.jdbc.driver.OracleDriver");
             }
             catch(ClassNotFoundException ex){    
            	 System.out.println(ex);
                ok = false;
             }
             //conn=DriverManager.getConnection("jdbc:odbc:"+Param.Base(),"","");
						 //jdbc:postgresql://h�te:port/base_de_donn�es
						 //System.out.println("utilisateur � partir de base = "+FAuth.Util());
						 //conn=DriverManager.getConnection("jdbc:postgresql://"+Param.ServeurBase()+":5432/"+Param.Base(), FAuth.Util(), FAuth.Pass());
						// conn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/CodeInstance", "adm", "adm");
			 			//conn=DriverManager.getConnection("jdbc:postgresql://192.168.0.160:5432/Recharge", "adm", "expert");
             conn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/test", "postgres","Service;Technique");
             System.out.println("connexion etabli");

						 //DriverManager.getConnection("jdbc:oracle:thin:@oban:1521:test", user, passwd);
             ok = true;
        }
        catch (SQLException e) {
             ok = false;
        	 System.out.println(e);
        	 System.out.println("CONNECT BASE");
        	 System.out.println("LogBase"+e.toString()+"dbConnect");
        	 JOptionPane.showMessageDialog(null,e.toString(),"Message",JOptionPane.ERROR_MESSAGE);			 
        }
	return ok;
   }

    
    public boolean dbDisconnect() {
 	boolean ok;              
	try {
            //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Class.forName("org.postgresql.Driver");
						conn.close();
            ok = true;
        }
        catch (Exception e) {
            ok = false;
            System.out.println("LogBase"+e.toString()+"Base"+"boolean dbDisconnect()");
            JOptionPane.showMessageDialog(null,e.toString(),"Message",JOptionPane.ERROR_MESSAGE);
	}
	return ok;
    }
    
    
    public Connection getConn() {
	return conn;
    }





}





